<?php

class It_Model_Users extends Zend_Db_Table_Abstract
{
    protected $_name = 'users';
    public function getUserByUsername($username)
    {
    	$query = $this->select();
        $query->from($this->_name,array('userId', 'username', 'password', 'status'));
        $query->where('username = ?', $username);
        return $this->fetchRow($query);
    }
    public function getUserById($id)
    {
    	$query = $this->select();
        $query->from($this->_name,array('userId', 'username', 'password', 'status'));
        $query->where('userId = ?', $id);
        return $this->fetchRow($query);
    }
    public function updatePass ($userId, $password)
    {
        $data['password'] = $password;
        $this->update($data, "userId = $userId");
    }
    public function deleteUser ($userId)
    {
        $this->delete('userId =' . (int) $userId);  
    }
    public function updateUser ($userId, $username, $password, $status)
    {
    	if($password){
    		 $data = array ('username' => $username ,'password' => md5( $password ), 'status' => $status);
    	}else{
    		 $data = array ('username' => $username, 'status' => $status);
    	}
        $this->update( $data, 'userId=' . (int) $userId );
    }
    public function getAllData()
    {
    	$query = $this->select();
        $query->from($this->_name,array('userId','username','status'));
        $query->where('1');
    	return $this->fetchAll($query);
    }
    public function addUser ($username, $password, $status)
    {
    	$data = array ( 'username' => $username, 'password' => md5( $password ), 'status' => $status);
        return $this->insert( $data );
    }
}

